// 入口文件
import Vue from 'vue'
import App from './App.vue'
import router from './router'
import ElementUI, { Tree } from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import './assets/css/global.css'
import './assets/fonts/iconfonts/iconfont.css'
import axios from 'axios'
import TreeTable from 'vue-table-with-tree-grid'
import VueQuillEditor from 'vue-quill-editor'
// require styles
import 'quill/dist/quill.core.css'
import 'quill/dist/quill.snow.css'
import 'quill/dist/quill.bubble.css'
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'


// 设置默认请求头
axios.defaults.baseURL = 'http://127.0.0.1:8888/api/private/v1/'
axios.interceptors.request.use(con => {
  // console.log(con);
  // 手动设置token 本来没有这个属性
  con.headers.Authorization = window.sessionStorage.getItem('browserToken')
  NProgress.start()
  return con;
})
axios.interceptors.response.use(con=>{
  NProgress.done()
  return con;
})
// 挂载到vue实例上。以后每一个vue实例可以通过this.$axios访问axios
Vue.prototype.$axios = axios;
// 全局的时间戳过滤器 过滤器记得要return出去
Vue.filter('dateFormat', originValue => {
  const date = new Date(originValue)
  //'x'.padStart(5, 'ab') // 'ababx'
  //'x'.padStart(4, 'ab') // 'abax'
  let Y = (date.getFullYear() + '').padStart(2, '0')
  let M = (date.getMonth() + 1 + '').padStart(2, '0')
  let D = (date.getDate() + '').padStart(2, '0')
  let h = (date.getHours() + '').padStart(2, '0')
  let m = (date.getMinutes() + '').padStart(2, '0')
  let s = (date.getSeconds() + '').padStart(2, '0')
  return `${Y}年${M}月${D}日 ${h}:${m}:${s}`
})

Vue.config.productionTip = false
Vue.use(ElementUI)
Vue.use(VueQuillEditor)
Vue.component('tree-table', TreeTable)
// 最后一步new一个实例
new Vue({
  router,
  render: h => h(App)
}).$mount('#app')
